//更新基本信息
function storeBasic() {
  var data = {
    id: $.cookie('id'),
    name: $("[name=name]").val(),
    sex: $("[name=sex]:checked").val(),
    phone: $("[name=phone]").val(),
    email: $("[name=email]").val(),
    birthday: $("[name=birthday]").val(),
    specialty: $("[name=specialty]").val(),
    homeland: $("[name=homeland]").val(),
    politic: $("[name=politic]").val(),
    nationality: $("[name=nationality]").val(),
    evaluate: $("[name=evaluate]").val(),
    skills: $("[name=skills]").val(),
    others: $("[name=others]").val(),
    college: "0",
    photourl: "xx"
  }
  console.log(data);
  $.ajax({
    url: "http://localhost:3000/basic/userBasic",
    type: 'post',
    data: data,
    dataType: 'json',
    success: function (result) {
      console.log(result);
      if (result.code == 1) {
        layer.msg("修改成功");
      }
    },
    error: function (msg) {

    }
  })
}
//添加教育经历
function addEdu() {
  var data = {
    id: $.cookie('id'),
    start_time: $("[name=edu_start_time]").val(),
    end_time: $("[name=edu_end_time]").val(),
    education_exp: $("[name=edu_exp]").val(),
    diploma: $("[name=diploma").val()
  }
  console.log(data);
  $.ajax({
    url: "http://localhost:3000/edu/userEdu",
    type: 'post',
    data: data,
    dataType: 'json',
    success: function (result) {
      console.log(result);
      var diploma_exp;
      if (result.code == 1) {
        layer.msg("添加成功");
        if (data.diploma == 0) {
          diploma_exp = "本科";
        } else if (data.diploma == 1) {
          diploma_exp = "硕士";
        } else {
          diploma_exp = "博士";
        }
        $("#education_all").append("<div class='layui-colla-item'>\
          <h2 class='layui-colla-title'>" + diploma_exp + "\
          <button class = 'layui-btn layui-btn-sm layui-btn-warm' style='float:right' onclick='deleteEdu(this," + result.id +
          ")'><i class = 'layui-icon'> &#xe640;</i></button>\
          </h2>\
          <div class='layui-colla-content'>\
          <p>" + data.start_time + "至" + data.end_time + "</p>\
          <p>" + data.education_exp + "</p>\
         </div>\
       </div>");
      }
      layui.element.render();
    },
    error: function (msg) {

    }
  })
}
//工作经历
function addPra() {
  var data = {
    id: $.cookie('id'),
    start_time: $("[name=pra_start_time]").val(),
    end_time: $("[name=pra_end_time]").val(),
    practice_exp: $("[name=practice_exp]").val(),
    company: $("[name=company]").val()
  }
  $.ajax({
    url: "http://localhost:3000/practice/userPractice",
    type: 'post',
    data: data,
    dataType: 'json',
    success: function (result) {
      console.log(result)
      if (result.code == 1) {
        layer.msg("添加成功");
        $("#practice_all").append("<div class='layui-colla-item'>\
          <h2 class='layui-colla-title'>" + data.company + "\
          <button class = 'layui-btn layui-btn-sm layui-btn-warm' style='float:right' onclick='deletePra(this," + result.id +
          ")'><i class = 'layui-icon'> &#xe640;</i></button>\
          </h2>\
          <div class='layui-colla-content'>\
          <p>" + data.start_time + "至" + data.end_time + "</p>\
          <p>" + data.practice_exp + "</p>\
         </div>\
       </div>");
      }
      layui.element.render();
    },
    error: function (msg) {

    }
  })
}
//项目经历
function addPro() {
  var data = {
    id: $.cookie('id'),
    start_time: $("[name=pro_start_time]").val(),
    end_time: $("[name=pro_end_time]").val(),
    project_exp: $("[name=project_exp]").val(),
    title: $("[name=title]").val()
  }
  $.ajax({
    url: "http://localhost:3000/project/userProject",
    type: 'post',
    data: data,
    dataType: 'json',
    success: function (result) {
      console.log(result)
      if (result.code == 1) {
        layer.msg("添加成功");
        $("#project_all").append("<div class='layui-colla-item'>\
          <h2 class='layui-colla-title'>" + data.title + "\
          <button class = 'layui-btn layui-btn-sm layui-btn-warm' style='float:right' onclick='deletePro(this," + result.id +
          ")'><i class = 'layui-icon'> &#xe640;</i></button>\
          </h2>\
          <div class='layui-colla-content'>\
          <p>" + data.start_time + "至" + data.end_time + "</p>\
          <p>" + data.project + "</p>\
         </div>\
       </div>");
      }
      layui.element.render();
    },
    error: function (msg) {
      alert(msg);
    }
  })
}
//添加获奖记录
function addHon() {
  var data = {
    id: $.cookie('id'),
    honor: $("[name=honor_exp]").val()
  }
  console.log(data);
  $.ajax({
    url: "http://localhost:3000/honor/userHonor",
    type: 'post',
    data: data,
    dataType: 'json',
    success: function (result) {
      console.log(result)
      if (result.code == 1) {
        layer.msg("保存成功");
        $("#honor_all").append("<div class='layui-colla-item'>\
        <h2 class='layui-colla-title'>" + data.honor + "\
        <button class = 'layui-btn layui-btn-sm layui-btn-warm' style='float:right' onclick='deleteHon(this," + result.id +
          ")'><i class = 'layui-icon'> &#xe640;</i></button>\
        </h2>\
        </div>");
      }
      layui.element.render();
    },
    error: function (msg) {
      alert(msg);
    }
  })
}
//自我评价
function addEvaluate() {
  var data = {
    id: $.cookie('id'),
    evaluate: $("[name=evaluate]").val()
  }
  console.log(data);
  $.ajax({
    url: "http://localhost:3000/evaluate/userEvaluate",
    type: 'post',
    data: data,
    dataType: 'json',
    success: function (result) {
      console.log(result)
      if (result.code == 1) {
        layer.msg("保存成功");
      }
      layui.element.render();
    },
    error: function (msg) {
      alert(msg);
    }
  })
}
//其他信息
function addOthers() {
  var data = {
    id: $.cookie('id'),
    others: $("[name=others]").val()
  }
  $.ajax({
    url: "http://localhost:3000/others/userOthers",
    type: 'post',
    data: data,
    dataType: 'json',
    success: function (result) {
      console.log(result)
      if (result.code == 1) {
        layer.msg("保存成功");
      }
      layui.element.render();
    },
    error: function (msg) {
      alert(msg);
    }
  })
}
//个人技能
function addSkills() {
  var data = {
    id: $.cookie('id'),
    skills: $("[name=skills]").val()
  }
  $.ajax({
    url: "http://localhost:3000/skills/userSkills",
    type: 'post',
    data: data,
    dataType: 'json',
    success: function (result) {
      console.log(result)
      if (result.code == 1) {
        layer.msg("保存成功");
      }
      layui.element.render();
    },
    error: function (msg) {
      alert(msg);
    }
  })
}
//创建简历
function CreateResume() {
  layer.open({
    type: 2,
    area: ['500px', '720px'],
    title: '创建简历',
    content: 'http://localhost:3000/users/resume',
    shade: 0,
    btn: ['前往编辑'],
    btn1: function (index, layero) {
      window.open("http://localhost:3000/users/resume");
      // window.print();
      //  var data ={
      //    url:"http://localhost:3000/users/resume",
      //    pdfName:$("[name=name]").val()
      //  }
      //  $.ajax({
      //   url: "http://localhost:3000/create/userPdf",
      //   type: 'post',
      //   data: data,
      //   dataType: 'json',
      //   success: function (result) {
      //     console.log(result)
      //   },
      //   error: function (msg) {
      //     alert(msg);
      //   }
      // })
    },
    cancel: function (layero, index) {
      layer.closeAll();
    }
  });
}